<!DOCTYPE html>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="format-detection" content="telephone=no">
    <title>设置-个人信息</title>
    <link rel="icon" href="/assets/img/favicon.ico">

    <!--cropper-->
    <link rel="stylesheet" href="css/cropper/cropper.min.css">
    <link rel="stylesheet" href="css/cropper/ImgCropping.css">

    <link rel="stylesheet" type="text/css" href="css/webbase.css" />
    <link rel="stylesheet" type="text/css" href="css/pages-seckillOrder.css" />

    <style>
        .str {
            width: 150px;
            height: 150px;
            border: solid 1px #e3e3e3;
            padding: 5px;
            margin-top: 10px
        }
    </style>
</head>

<body>
<!--页面顶部白条条，由js动态加载-->
<script type="text/javascript" src="plugins/jquery/jquery.min.js"></script>
<div class="nav-bottom"></div>
<script type="text/javascript">$(".nav-bottom").load("top.html");</script>
<!--cropper-->
<script src="js/cropper/cropper.min.js"></script>
<script type="text/javascript">
    $(function(){
        $("#service").hover(function(){
            $(".service").show();
        },function(){
            $(".service").hide();
        });
        $("#shopcar").hover(function(){
            $("#shopcarlist").show();
        },function(){
            $("#shopcarlist").hide();
        });

    })
</script>
<script type="text/javascript" src="js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="js/widget/nav.js"></script>
<script type="text/javascript" src="js/plugins/birthday/birthday.js"></script>
<script type="text/javascript" src="js/plugins/citypicker/distpicker.data.js"></script>
<script type="text/javascript" src="js/plugins/citypicker/distpicker.js"></script>
<script type="text/javascript" src="js/plugins/upload/uploadPreview.js"></script>
<script type="text/javascript" src="js/pages/main.js"></script>
<script>
    $(function() {
        $.ms_DatePicker({
            YearSelector: "#select_year2",
            MonthSelector: "#select_month2",
            DaySelector: "#select_day2"
        });
    });
</script>
</body>
<!--header-->
<div id="account">
    <div class="py-container">
        <div class="yui3-g home">
            <!--左侧列表-->
            <div class="yui3-u-1-6 list">

                <div class="person-info">
                    <div class="person-photo"><img :src="userDetail.image" alt=""></div>
                    <div class="person-account">
                        <span class="name">{{user.username}}</span>
                        <span class="safe">账户安全</span>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="list-items">
                    <dl>
                        <dt><i>·</i> 订单中心</dt>
                        <dd ><a href="home-index.html"   >我的订单</a></dd>
                        <dd><a href="home-order-pay.html" >待付款</a></dd>
                        <dd><a href="home-order-send.html"  >待发货</a></dd>
                        <dd><a href="home-order-receive.html" >待收货</a></dd>
                        <dd><a href="home-evaluate.html" >待评价</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 我的中心</dt>
                        <dd><a href="home-person-collect.html" >我的收藏</a></dd>
                        <dd><a href="home-person-footmark.html" >我的足迹</a></dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 物流消息</dt>
                    </dl>
                    <dl>
                        <dt><i>·</i> 设置</dt>
                        <dd><a href="home-setting-info.html" class="list-active">个人信息</a></dd>
                        <dd><a href="home-setting-address.html"  >地址管理</a></dd>
                        <dd><a href="home-setting-safe.html" >安全管理</a></dd>
                    </dl>
                </div>
            </div>
            <!--右侧主内容-->
            <div class="yui3-u-5-6">
                <div class="body userInfo">
                    <ul class="sui-nav nav-tabs nav-large nav-primary ">
                        <li class="active"><a href="#one" data-toggle="tab">基本资料</a></li>
                        <li><a href="#two" data-toggle="tab">头像照片</a></li>
                    </ul>
                    <div class="tab-content ">
                        <div id="one" class="tab-pane active" >
                            <!--                            //原来位置-->
                            <form id="form-msg" style="display: none" class="sui-form form-horizontal">
                                <div class="control-group">
                                    <label for="inputName" class="control-label">昵称：</label>
                                    <div class="controls">
                                        <input type="text" id="inputName" name="email" v-model="userDetail.userName" placeholder="昵称">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputGender" class="control-label">性别：</label>
                                    <div class="controls">
                                        <label data-toggle="radio" class="radio-pretty inline">
                                            <input type="radio" name="gender" value="1" v-model="userDetail.gender"><span>男</span>
                                        </label>
                                        <label data-toggle="radio" class="radio-pretty inline">
                                            <input type="radio" name="gender" value="0" v-model="userDetail.gender"><span>女</span>
                                        </label>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputPassword" class="control-label">生日：</label>
                                    <div class="controls">
                                        <select id="select_year2" rel="1990"></select>年
                                        <select id="select_month2" rel="4"></select>月
                                        <select id="select_day2" rel="3"></select>日
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputPassword" class="control-label">所在地：</label>
                                    <div class="controls">
                                        <div data-toggle="distpicker">
                                            <div class="form-group area">
                                                <select class="form-control" id="province1" ></select>
                                            </div>
                                            <div class="form-group area">
                                                <select class="form-control" id="city1"></select>
                                            </div>
                                            <div class="form-group area">
                                                <select class="form-control" id="district1"></select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="inputJob" class="control-label">职业：</label>
                                    <div class="controls"><span class="sui-dropdown dropdown-bordered select"><span class="dropdown-inner"><a role="button" data-toggle="dropdown" href="#" class="dropdown-toggle">
                                                <input id="job"  type="hidden" data-rules="required" ><i class="caret"></i><span>请选择</span></a>
                                            <ul id="menu4" role="menu" aria-labelledby="drop4" class="sui-dropdown-menu" >
                                                <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:void(0);" value="程序员">程序员</a></li>
                                                <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:void(0);" value="产品经理">产品经理</a></li>
                                                <li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:void(0);" value="UI设计师">UI设计师</a></li>
                                            </ul>
                                            </span>
                                            </span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="sanwei" class="control-label"></label>
                                    <div class="controls">
                                        <button type="button"  class="sui-btn btn-primary" @click="upload()">立即注册</button>
                                    </div>
                                </div>
                            </form>
                            <!-- 显示当前用户的详情 -->
                            <div id="userInfo" style="display: block;margin-left: 40px" >
                                <div class="control-group">
                                    <label for="inputName" class="control-label">头像：</label> &nbsp;&nbsp;
                                    <img  v-bind:src="userDetail.image" alt="" style="width: 48px;height: 48px">
                                </div>
                                <br>
                                <div class="control-group">
                                    <label for="inputName" class="control-label">昵称：</label> &nbsp;&nbsp;{{userDetail.userName}}
                                </div>
                                <br>
                                <div class="control-group">
                                    <label for="inputName" class="control-label">性别：</label> &nbsp;&nbsp;{{userDetail.gender}}
                                </div>
                                <br>
                                <div class="control-group">
                                    <label for="inputName" class="control-label">生日：</label> &nbsp;&nbsp;{{userDetail.birthday}}
                                </div>
                                <br>
                                <div class="control-group">
                                    <label for="inputName" class="control-label">地址：</label> &nbsp;&nbsp;{{userDetail.address}}
                                </div>
                                <br>
                                <div class="control-group">
                                    <label for="inputName" class="control-label">职业：</label> &nbsp;&nbsp;{{userDetail.occupation}}
                                </div>
                            </div>


                        </div>
                        <div id="two" class="tab-pane">
                            <!--                            <div class="new-photo">-->
                            <!--                                <p>当前头像：</p>-->
                            <!--                                <form-->
                            <!--                                        id="ss"  method="post" enctype="multipart/form-data">-->
                            <!--                                <div class="upload">-->
                            <!--                                    <img id="imgShow_WU_FILE_0" width="100" height="100" src="img/_/photo_icon.png" alt="">-->
                            <!--                                    <input type="file" id="up_img_WU_FILE_0" name="file" /><br>-->
                            <!--                                    <button type="button" @click="uploadImg()">上传</button>-->
                            <!--                                </div>-->
                            <!--                                </form>-->
                            <!--                            </div>-->
                            <form
                                    id="ss"  method="post" enctype="multipart/form-data">
                                <div class="str">
                                    <img id="finalImg" src="img/_/photo_icon.png" width="100%">
                                </div>
                                <br>
                                <label title="上传图片" for="chooseImg" class="l-btn choose-btn">
                                    <input type="file" accept="image/jpg,image/jpeg,image/png" name="file" id="chooseImg" class="hidden" onchange="selectImg(this)">
                                    选择图片
                                </label>
                            </form>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<!-- 底部栏位 -->
<!--页面底部，由js动态加载-->
<div class="clearfix footer"></div>
<script type="text/javascript">$(".footer").load("foot.html");</script>
<!--页面底部END-->
<script src="./js/vue/vue.js"></script>
<script src="./js/axios.min.js"></script>
<script src="./js/common.js"></script>
<script src="js/jquery.form.js"></script>
<script type="text/javascript">
    const userVm = new Vue({
        el : "#account",
        data:{
            ly,
            user:{},
            userDetail:{
                userName : "",
                gender : "",
                birthday : "",
                address : "",
                occupation : "",
                image : "",
            }
        },
        async created() {
            ly.http.get("/auth/verify").then(resp=>{
                this.user=resp.data;
                this.loadUserInfo();
            })

        },
        methods:{
            //查询用户信息
            loadUserInfo:function(){
                ly.http.get("user/detail").then((response) =>{
                    this.userDetail = response.data;
                    $('#userInfo').show();
                    $('#form-msg').hide();
                    console.log(response.data)
                }).catch((err) =>{
                    $('#userInfo').hide();
                    $('#form-msg').show();
                });
            },
            //注册
            upload:function () {
                this.userDetail.address = this.addr;
                this.userDetail.birthday = this.birth;
                this.userDetail.occupation = this.job;
                ly.http.post("user/detail",this.userDetail).then((response) =>{
                    successInfo();
                    location.reload();
                });
            },
        },
        computed:{
            addr(){
                return $('#province1 option:selected').text() + " " +
                    $('#city1 option:selected').text() + " " +
                    $('#district1 option:selected').text() + " ";
            },
            birth(){
                let year = $('#select_year2 option:selected').text();
                let month = $('#select_month2 option:selected').text();
                let day = $('#select_day2 option:selected').text();
                if (month.length !== 2) {
                    month = "0" + month;
                }
                if (day !== 2) {
                    day = "0" + day;
                }

                return year + "-" + month + "-" + day;
            },
            job(){
                return $('#job').val();
            }
        }
    });

    function errInfo() {
        alert("操作失败啦 图片上传失败");
    }
    function successInfo() {
        alert("恭喜操作成功 图片上传成功");
    }
</script>

<!--图片裁剪框 start-->
<div style="display: none" class="tailoring-container">
    <div class="black-cloth" onclick="closeTailor(this)"></div>
    <div class="tailoring-content">
        <div class="tailoring-content-one">

            <div class="close-tailoring" onclick="closeTailor(this)">×</div>
        </div>

        <div class="tailoring-content-two">
            <div class="tailoring-box-parcel">
                <img id="tailoringImg">
            </div>
            <div class="preview-box-parcel">
                <p>图片预览：</p>
                <div class="square previewImg"></div>
                <!--  <div class="circular previewImg"></div>-->
            </div>
        </div>

        <div class="tailoring-content-three">
            <button class="l-btn cropper-reset-btn">复位</button>
            <button class="l-btn cropper-rotate-btn">旋转</button>
            <button class="l-btn cropper-scaleX-btn">换向</button>
            <button class="l-btn sureCut" id="sureCut">确定</button>
        </div>
    </div>
</div>
<!--图片裁剪框 end-->

<!--cropper-->
<script type="text/javascript">
    //弹出框水平垂直居中
    (window.onresize = function() {
        var win_height = $(window).height();
        var win_width = $(window).width();
        if (win_width <= 768) {
            $(".tailoring-content").css(
                {
                    "top" : (win_height - $(".tailoring-content")
                        .outerHeight()) / 2,
                    "left" : 0
                });
        } else {
            $(".tailoring-content").css(
                {
                    "top" : (win_height - $(".tailoring-content")
                        .outerHeight()) / 2,
                    "left" : (win_width - $(".tailoring-content")
                        .outerWidth()) / 2
                });
        }
    })();

    // 选择文件触发事件
    function selectImg(file) {
        //文件为空，返回
        if (!file.files || !file.files[0]) {
            return;
        }
        $(".tailoring-container").toggle();
        var reader = new FileReader();
        reader.onload = function(evt) {
            var replaceSrc = evt.target.result;
            // 更换cropper的图片
            $('#tailoringImg').cropper('replace', replaceSrc, false);// 默认false，适应高度，不失真
        }
        reader.readAsDataURL(file.files[0]);
    }
    // cropper图片裁剪
    $('#tailoringImg').cropper({
        aspectRatio : 1 / 1,// 默认比例
        preview : '.previewImg',// 预览视图
        guides : false, // 裁剪框的虚线(九宫格)
        autoCropArea : 0.5, // 0-1之间的数值，定义自动剪裁区域的大小，默认0.8
        movable : false, // 是否允许移动图片
        dragCrop : true, // 是否允许移除当前的剪裁框，并通过拖动来新建一个剪裁框区域
        movable : true, // 是否允许移动剪裁框
        resizable : true, // 是否允许改变裁剪框的大小
        zoomable : false, // 是否允许缩放图片大小
        mouseWheelZoom : false, // 是否允许通过鼠标滚轮来缩放图片
        touchDragZoom : true, // 是否允许通过触摸移动来缩放图片
        rotatable : true, // 是否允许旋转图片
        crop : function(e) {
            // 输出结果数据裁剪图像。
        }
    });
    // 旋转
    $(".cropper-rotate-btn").on("click", function() {
        $('#tailoringImg').cropper("rotate", 45);
    });
    // 复位
    $(".cropper-reset-btn").on("click", function() {
        $('#tailoringImg').cropper("reset");
    });
    // 换向
    var flagX = true;
    $(".cropper-scaleX-btn").on("click", function() {
        if (flagX) {
            $('#tailoringImg').cropper("scaleX", -1);
            flagX = false;
        } else {
            $('#tailoringImg').cropper("scaleX", 1);
            flagX = true;
        }
        flagX != flagX;
    });

    // 确定按钮点击事件
    $("#sureCut").on("click", function() {
        if ($("#tailoringImg").attr("src") == null) {
            return false;
        } else {
            var cas = $('#tailoringImg').cropper('getCroppedCanvas');// 获取被裁剪后的canvas
            var base64 = cas.toDataURL('image/jpeg'); // 转换为base64

            $("#finalImg").prop("src", base64);// 显示图片
            uploadFile(encodeURIComponent(base64))//编码后上传服务器
            closeTailor();// 关闭裁剪框
        }
    });

    // 关闭裁剪框
    function closeTailor() {
        $(".tailoring-container").toggle();
    }

    //ajax请求上传
    function uploadFile(file) {
        $.ajax({
            url : 'http://api.leyou.com/api/upload/images/',
            type : 'POST',
            data : "file=" + file,
            async : true,
            success : function(data) {
                userVm.userDetail.image = data;
                successInfo();
            },
            error:function (err) {
                errInfo();
            }
        });
    }
</script>

</html>